//
//  SKTView.m
//  何五路
//
//  Created by _ADY on 15/6/13.
//  Copyright (c) 2015年 _ADY. All rights reserved.
//

#import "SKTView.h"

static LoadingView *loading = nil;

@implementation SKTView
@synthesize allArray,productId,delegate;
#define butBag 2000000
#define butBag1 200000000
#define barTagButton 1000000
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        vFrame = frame;
        

        myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height - 60)];
        myTableView.delegate = self;
        myTableView.dataSource = self;
        myTableView.backgroundColor = [UIColor clearColor];
        [self addSubview:myTableView];
        
        UIView *v = [[UIView alloc] initWithFrame:CGRectZero];//清除多余分割线
        [myTableView setTableFooterView:v];
         pSgtring = nil;
        JGlInt = 1;
        [self toolbar];
        [self performSelector:@selector(after) withObject:nil afterDelay:1];
    }
    return self;
}

-(void)after
{
//    NSLog(@"allArray %@",allArray);
    aParray = [[NSMutableArray alloc] init];
    NSMutableArray *myArray = [[NSMutableArray alloc] init];
    if ([[allArray allKeys] containsObject:@"ProductAttributes"])
    {
//        NSLog(@"ad %@",[allArray objectForKey:@"ProductAttributes"]);
        
        for (NSDictionary *pic1 in [allArray objectForKey:@"ProductAttributes"])
        {
            
            if ([[pic1 allKeys] containsObject:@"Values"])
            {
                for (NSDictionary *pic in [pic1 objectForKey:@"Values"])
                {
                    [myArray addObject:pic];
                    if ([[NSString stringWithFormat:@"%@",[pic objectForKey:@"IsPreSelected"]] isEqualToString:@"1"]) {
                        imgString = [NSString stringWithFormat:@"%@",[pic objectForKey:@"PictureBigUrl"]];
                    }
                }
                [aParray addObject:pic1];
            }
        }

    }
   
    [self gotoRem];

    [myTableView reloadData];
//    NSLog(@"myArray %@",myArray);
}
#pragma mark 算库存量
-(void)gotoRem
{
    
    /*购物车商品库存相关属性
     
     Model.Items[i].TrackStockType // 0:不跟踪库存，1：跟踪商品库存，2：跟踪商品属性库存
     Model.Items[i].StockQuantity  //商品库存数量
     Model.Items[i].StockQuantityAttr //商品属性库存数量
     */
    // minInt,maxInt,remainInt;//最小 最大 剩余
    if ([[allArray allKeys] containsObject:@"AddToCart"])
    {
        NSDictionary *pic =[allArray objectForKey:@"AddToCart"];
        
        remainInt = [[NSString stringWithFormat:@"%@",[pic objectForKey:@"StockQuantity"]] intValue];
        maxInt = [[NSString stringWithFormat:@"%@",[pic objectForKey:@"OrderMaximumQuantity"]] intValue];
        minInt = [[NSString stringWithFormat:@"%@",[pic objectForKey:@"OrderMinimumQuantity"]] intValue];
        
        if ([[NSString stringWithFormat:@"%@",[pic objectForKey:@"ManageInventoryMethodId"]] isEqualToString:@"0"])
        {
            remainInt = maxInt;
        }
        else if ([[NSString stringWithFormat:@"%@",[pic objectForKey:@"ManageInventoryMethodId"]] isEqualToString:@"1"])
        {
            maxInt = remainInt;
        }
        else if ([[NSString stringWithFormat:@"%@",[pic objectForKey:@"ManageInventoryMethodId"]] isEqualToString:@"2"])
        {
            NSMutableArray *myArray = [[NSMutableArray alloc] init];
            
            for (NSDictionary *dic in aParray)
            {
                NSMutableDictionary *postDic = [[NSMutableDictionary alloc] init];
                [postDic setObject:[dic objectForKey:@"ProductAttributeId"] forKey:@"AttributeId"];
               for (NSDictionary *pic in [dic objectForKey:@"Values"])
               {
                   if ([[NSString stringWithFormat:@"%@",[pic objectForKey:@"IsPreSelected"]] isEqualToString:@"1"])
                   {
                      [postDic setObject:[pic objectForKey:@"Id"] forKey:@"AttributeValueId"];
                   }
               }
                [myArray addObject:postDic];
            }
            loading = [[LoadingView alloc] initWithFrame:screenMySize];
            [[UIApplication sharedApplication].keyWindow addSubview:loading];
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                NSDictionary *ret = [SendService GetProductInfoByAttribute:productId source:myArray];
                dispatch_async(dispatch_get_main_queue(), ^{
                    [loading closeLoading];
//                    NSLog(@"ret2313 %@",ret);
                    if (ret !=nil)
                    {
                        if (![[NSString  stringWithFormat:@"%@",[ret objectForKey:@"Entity"]] isEqualToString:@"<null>"])
                        {
                            remainInt =[[[ret objectForKey:@"Entity"] objectForKey:@"StockQuantity"] intValue];
                            if (maxInt > remainInt) {
                                maxInt = remainInt;
                            }
                            pSgtring = [[ret objectForKey:@"Price"] objectForKey:@"StockQuantity"];
                        }
                    }

                    
                    [myTableView reloadData];
                });
            });
        }
    }
    if (![imgString hasPrefix:@"http"])
    {
        NSMutableArray *my2Array = [[NSMutableArray alloc] init];
        if ([[allArray allKeys] containsObject:@"PictureModels"])
        {
            for (NSDictionary *pic in [allArray objectForKey:@"PictureModels"])
            {
                [my2Array addObject:pic];
            }
        }
        else if ([[allArray allKeys] containsObject:@"DefaultPictureModel"])
        {
            for (NSDictionary *pic in [allArray objectForKey:@"DefaultPictureModel"])
            {
                [my2Array addObject:pic];
            }
        }
        if (my2Array.count>0) {
            imgString = [NSString stringWithFormat:@"%@",[[my2Array objectAtIndex:0] objectForKey:@"BigImgageUrl"]];
        }
        
    }
    if (remainInt == 0) {
        JGlInt = 0;
    }
}
-(void)toolbar
{
    UIView *barView = [[UIView alloc] initWithFrame:CGRectMake(0, vFrame.size.height-60, vFrame.size.width, 60)];
    barView.backgroundColor = [UIColor clearColor];
    [self addSubview:barView];
    
    for (int  i = 0; i < 2; i++)
    {
        UIButton *barButton = [UIButton buttonWithType:UIButtonTypeCustom];
        barButton.frame = CGRectMake(0+i*vFrame.size.width/2+i, 0,vFrame.size.width/2, 59);
        [barButton addTarget:self action:@selector(barAction:) forControlEvents:UIControlEventTouchUpInside];
        if (i == 0)
            [barButton setTitle:@"加入购物车" forState:UIControlStateNormal];
        else if (i == 1)
            [barButton setTitle:@"立即购买" forState:UIControlStateNormal];
        [barButton setBackgroundColor:[UIColor colorWithRed:248/255.0 green:181/255.0 blue:0/255.0 alpha:1]];
        [barButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        barButton.tag = barTagButton +i;
        barButton.titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize+3];
        [barView addSubview:barButton];
        
    }
}

-(void)loginAction
{
    LoginViewController *browser = [[LoginViewController alloc] init];
    browser.hidesBottomBarWhenPushed = YES;
    [self.delegate setController:browser];
}

#pragma mark 加入购物车、立即购买
-(void)barAction:(id)sender
{
    BOOL aLogin = [[NSUserDefaults standardUserDefaults] boolForKey:@"isLoginKey"];
    if (!aLogin) {
        [self loginAction];
        return;
    }
    
    int  type = ((UIButton*)sender).tag -barTagButton;
    if (type == 0 || type == 1)
    {
        NSMutableDictionary *postDic1 = [[NSMutableDictionary alloc] init];
        [postDic1 setObject:productId forKey:@"productId"];
        [postDic1 setObject:@"1" forKey:@"shoppingCartTypeId"];
        [postDic1 setObject:textField.text forKey:[NSString stringWithFormat:@"addtocart_%@.EnteredQuantity",productId]];

        if (aParray.count != 0)
        {
            for (NSDictionary *pic1 in aParray)
            {
                if ([[NSString  stringWithFormat:@"%@",[pic1 objectForKey:@"IsRequired"]] isEqualToString:@"1"])
                {
                    if ([[pic1 allKeys] containsObject:@"Values"])
                    {
                        for (NSDictionary *pic in [pic1 objectForKey:@"Values"])
                        {
                            if ([[NSString stringWithFormat:@"%@",[pic objectForKey:@"IsPreSelected"]] isEqualToString:@"1"]) {
                                
                                [postDic1 setObject:[NSString stringWithFormat:@"%@",[pic objectForKey:@"Id"]] forKey:[NSString stringWithFormat:@"product_attribute_%@_%@_%@",productId,[pic1 objectForKey:@"ProductAttributeId"],[pic1 objectForKey:@"Id"]]];
                            }
                        }
                    }
                    
                    
                    
                }
            }
        }
        loading = [[LoadingView alloc] initWithFrame:screenMySize];
        [[UIApplication sharedApplication].keyWindow addSubview:loading];
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSDictionary *myArray = [SendService AddProductToCart_DetailsTwo:postDic1];
            dispatch_async(dispatch_get_main_queue(), ^{
                //                NSLog(@"myarray %@",[myArray objectForKey:@"Message"]);
                [loading closeLoading];
                if ([[NSString stringWithFormat:@"%@",[myArray objectForKey:@"Result"]] isEqualToString:@"success"] && type == 1)
                {
                        [self.delegate _sideSlipViewShow];
                        ShoppingViewController *browser = [[ShoppingViewController alloc] init];
                        browser.hidesBottomBarWhenPushed = YES;
                        browser.aBarString = @"1";
                        [self.delegate setController:browser];
                }
                else
                    [SendService alerViewMessage:[myArray objectForKey:@"Message"]];
                
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                    NSDictionary *ret = [SendService GetShoppingCartCount];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        if (ret !=nil)
                        {
                            if ([[ret objectForKey:@"Result"] isEqualToString:@"success"])
                            {
                               
                                [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:@"%@",[[ret objectForKey:@"Entity"] objectForKey:@"ShoppingCartCount"]] forKey:@"ShoppingCartCountKey"];
                                 [self.delegate gotoSgwc];
                            }
                        }
                        
                    });
                });
            });
        });
    }
    
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return aParray.count+2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return vFrame.size.height/3;
    }
    else if (indexPath.row-1 < aParray.count)
    {
        NSMutableArray *act = [[aParray objectAtIndex:indexPath.row-1] objectForKey:@"Values"];
        return act.count*35;
    }
    return 50;
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        aTableView.showsVerticalScrollIndicator = NO;
    }
    int i = (int)[[cell.contentView subviews] count] - 1;
    for(;i >= 0 ; i--)
    {
        [[[cell.contentView subviews] objectAtIndex:i] removeFromSuperview];
    }
    aTableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    if (indexPath.row == 0)
    {
        return [self mCell:cell aCTableView:aTableView cellForRowAtIndexPath:indexPath];
    }
    else if (indexPath.row-1 < aParray.count)
        return [self mCell:cell bCTableView:aTableView cellForRowAtIndexPath:indexPath];
    else
        return [self mCell:cell cCTableView:aTableView cellForRowAtIndexPath:indexPath];
    
    // Configure the cell...
    return cell;
}

- (UITableViewCell *)mCell:(UITableViewCell*)cell aCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, vFrame.size.height/3-.5+1, vFrame.size.width, .5)];
    bgView.backgroundColor = [UIColor grayColor];
    [cell.contentView addSubview:bgView];
    
    UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(9.5,39.5, vFrame.size.width/2+1-20, ((screenMySize.size.height*3/5)*(vFrame.size.width/2))/screenMySize.size.width+1-20)];
    [bg1ImageView setImage:[UIImage imageNamed:@"gwckk"]];
    [cell.contentView addSubview:bg1ImageView];
    
    UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,40, vFrame.size.width/2-20, ((screenMySize.size.height*3/5)*(vFrame.size.width/2))/screenMySize.size.width-20)];
    [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",imgString]]];
    bgImageView.contentMode =  UIViewContentModeScaleAspectFit;
//    bgImageView.contentMode = UIViewContentModeScaleAspectFill;
    bgImageView.clipsToBounds  = YES;
    bgImageView.layer.masksToBounds = YES;
    bgImageView.layer.backgroundColor = (__bridge CGColorRef)([UIColor grayColor]);
    bgImageView.layer.cornerRadius = 5.0f;
    [cell.contentView addSubview:bgImageView];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15+vFrame.size.width/2,40, vFrame.size.width/2-15, 35)];
    titleLabel.textAlignment = 0;
    if (pSgtring == nil) {
        titleLabel.text = [[allArray objectForKey:@"ProductPrice"] objectForKey:@"Price"];
    }
    else
        titleLabel.text = pSgtring;
    
    titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize+2];
    titleLabel.textColor = [UIColor redColor];
    [cell.contentView addSubview:titleLabel];
    

    return cell;
}

- (UITableViewCell *)mCell:(UITableViewCell*)cell bCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * titleString = nil;
    if ([[NSString  stringWithFormat:@"%@",[[aParray objectAtIndex:indexPath.row-1] objectForKey:@"TextPrompt"]] isEqualToString:@"<null>"]) {
       titleString = [NSString  stringWithFormat:@"%@:",[[aParray objectAtIndex:indexPath.row-1] objectForKey:@"Name"]];
    }
    else
     titleString = [NSString  stringWithFormat:@"%@:",[[aParray objectAtIndex:indexPath.row-1] objectForKey:@"TextPrompt"]];
    int tyHight = [SendService setString:titleString setSize:labelSize setWight:25];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,5, tyHight, 25)];
    titleLabel.textAlignment = 0;
    titleLabel.text = titleString;
    titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize];
    titleLabel.textColor = [UIColor grayColor];
    [cell.contentView addSubview:titleLabel];
    
    int i = 0;
    for (NSDictionary *pic in [[aParray objectAtIndex:indexPath.row-1] objectForKey:@"Values"])
    {
        UIButton *barButton = [UIButton buttonWithType:UIButtonTypeSystem];
        barButton.frame = CGRectMake(10+tyHight, 5+35*i,100, 25);
        [barButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        barButton.titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize];
        [barButton setTitle:[pic objectForKey:@"Name"] forState:UIControlStateNormal];
        [barButton setBackgroundColor:[UIColor grayColor]];
        [barButton addTarget:self action:@selector(barbAction:) forControlEvents:UIControlEventTouchUpInside];
        barButton.tag = butBag +i +(indexPath.row-1)*butBag1;
        [cell.contentView addSubview:barButton];
        if ([[NSString stringWithFormat:@"%@",[pic objectForKey:@"IsPreSelected"]] isEqualToString:@"1"])
            [barButton setBackgroundColor:[UIColor colorWithRed:248/255.0 green:181/255.0 blue:0/255.0 alpha:1]];

        i++;
    }
    
    return cell;
}

- (UITableViewCell *)mCell:(UITableViewCell*)cell cCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,10, 40, 25)];
    titleLabel.textAlignment = 0;
    titleLabel.text = @"数量:";
    titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize];
    titleLabel.textColor = [UIColor grayColor];
    [cell.contentView addSubview:titleLabel];
    
    
    UIImage *loginImage = [UIImage imageNamed:@"jj_01"];
    UIImage *loginImage1 = [UIImage imageNamed:@"jj_00"];
    reButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [reButton setFrame:CGRectMake(50, 10, 51/2, 52/2)];
    [reButton setBackgroundImage:loginImage forState:UIControlStateNormal];
    [reButton setBackgroundImage:loginImage1 forState:UIControlStateDisabled];
    [reButton addTarget:self action:@selector(reAction) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:reButton];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"jj_02"]];
    imageView.frame = CGRectMake(50+51/2, 10, 80/2, 52/2);
    [cell.contentView addSubview:imageView];
    
    textField = [[UITextField alloc] initWithFrame:imageView.frame];
    textField.backgroundColor = [UIColor clearColor];
    [textField setFont:[UIFont systemFontOfSize:labelSize-1]];
    textField.returnKeyType = UIReturnKeyGo;
    textField.keyboardType = UIKeyboardTypeNumberPad;
    textField.delegate = self;
    textField.text = [NSString stringWithFormat:@"%d",JGlInt];
    textField.textAlignment = 1;
//    [textField setPlaceholder:@"请输入验证码"];
    [cell.contentView addSubview:textField];
    
    
    UIImage *loginImage2 = [UIImage imageNamed:@"jj_03"];
    UIImage *loginImage3 = [UIImage imageNamed:@"jj_04"];
    addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [addButton setFrame:CGRectMake(50+51/2+80/2, 10, 51/2, 52/2)];
    [addButton setBackgroundImage:loginImage2 forState:UIControlStateNormal];
    [addButton setBackgroundImage:loginImage3 forState:UIControlStateDisabled];
    [addButton addTarget:self action:@selector(addAction) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:addButton];
    
    
    UILabel *numLabel = [[UILabel alloc] initWithFrame:CGRectMake(50+51+80/2+10,10,SLIP_WIDTH-(50+51+80/2+10), 25)];
    numLabel.textAlignment = 0;
    if (remainInt == 0)
      numLabel.text = @"缺货";
    else
        numLabel.text = [NSString stringWithFormat:@"剩余%d",remainInt];
    numLabel.font = [UIFont fontWithName:@"Arial" size:labelSize];
    numLabel.textColor = [UIColor redColor];
    [cell.contentView addSubview:numLabel];
    
    return cell;
}

-(void)reAction
{
    int type = JGlInt;
    type = type - 1;
    if (type >= minInt && type <= maxInt) {
        textField.text = [NSString stringWithFormat:@"%d",type];
        JGlInt = type;
        addButton.enabled = YES;
        if (type == minInt) {
            reButton.enabled = NO;
        }
    }
    else
        reButton.enabled = NO;
    [self.delegate  returnSelected:JGlInt setNSM:aParray];
}

-(void)addAction
{
    int type = JGlInt;
    type = type + 1;
    if (type >= minInt && type <= maxInt) {
         textField.text = [NSString stringWithFormat:@"%d",type];
        JGlInt = type;
        reButton.enabled = YES;
        if (type == maxInt) {
            addButton.enabled = NO;
        }
    }
    else
        addButton.enabled = NO;
    [self.delegate  returnSelected:JGlInt setNSM:aParray];
}

-(void)barbAction:(id)sender
{
    int type = ((UIButton*)sender).tag;
    int row = type/butBag1;
    int index = type%butBag;
    
    int i = 0;
    NSMutableArray *mArray = [[NSMutableArray alloc] init];
    for (NSMutableDictionary *pic in [[aParray objectAtIndex:row] objectForKey:@"Values"])
    {
        NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithCapacity:10];
        [dic addEntriesFromDictionary:pic];
        [dic setObject:[NSString stringWithFormat:@"0"] forKey:@"IsPreSelected"];
        if (i == index)
        {
            [dic setObject:[NSString stringWithFormat:@"1"] forKey:@"IsPreSelected"];
            imgString = [NSString stringWithFormat:@"%@",[pic objectForKey:@"PictureBigUrl"]];
        }
        
        [mArray addObject:dic];
        i++;
    }
    NSDictionary *m = [aParray objectAtIndex:row];
    NSMutableDictionary *FlowSetting = [NSMutableDictionary dictionaryWithDictionary:m];
    [FlowSetting setValue:mArray forKey:@"Values"];

    [aParray setObject:FlowSetting atIndexedSubscript:row];
    [self.delegate  returnSelected:JGlInt setNSM:aParray];
    [self gotoRem];
    [myTableView reloadData];
    
}
#pragma mark 点击响应事件
- (void)tableView:(UITableView *)table1View didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [table1View deselectRowAtIndexPath:indexPath animated:YES];
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)text1Field
{
    [myTableView setContentOffset:CGPointMake(0, 100) animated:YES];
    [text1Field resignFirstResponder];
    return YES;
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)text1Field
{
    [myTableView setContentOffset:CGPointMake(0, 0) animated:YES];

    [text1Field resignFirstResponder];
    return YES;
}


//限制输入长度 by zwb 2011.9.6
- (BOOL)textField:(UITextField *)text1Field shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{

    NSString *text = [text1Field.text stringByReplacingCharactersInRange:range withString:string];
    int type = [text intValue];
    if (type < minInt || type > maxInt)
    {
        text1Field.text = [text1Field.text substringToIndex:[text1Field.text length] - 1];
    }
    else if (type == minInt)
    {
        reButton.enabled = NO;
    }
    else if (type ==  maxInt)
    {
        addButton.enabled = NO;
    }
    else
    {
        addButton.enabled = YES;
        reButton.enabled = YES;
    }
    JGlInt = [text intValue];
    [self.delegate  returnSelected:JGlInt setNSM:aParray];
    return YES;
    
}

//滚动或者触摸隐藏键盘
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [myTableView setContentOffset:CGPointMake(0, 0) animated:YES];
    
    [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [myTableView setContentOffset:CGPointMake(0, 0) animated:YES];
    [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
}
@end
